<template>
  <div class="stock">
    <span class="title">安全库存设置</span>
    <div class="lists">
      <div class="list" v-for="(item,index) in productLineList">
        <div class="list_title" @click="updatePro(item,4)">
          <span>{{item.name}}</span>
          <label>
            <span>{{item.value}}</span>
            <label>pcs</label>
          </label>
        </div>
        <div class="advance" @click="updatePro(item,5)">
          <div class="ad_left">提前期</div>
          <div class="ad_right">
            <span>{{item.leadTime}}</span>
            <label>天</label>
          </div>
        </div>
      </div>
    </div>
    <upstateProduct v-if="showUpstatePro" :updateProDate="updateProDate" @getBack="getBack" :upType="upType"></upstateProduct>
  </div>
</template>

<script>
  import upstateProduct from '../../../dialog/upstateProduct'
  import {mapGetters,mapActions} from 'vuex'
  export default {
    name: "stock",
    data() {
      return {
        productLineList: [],
        canOperation: false, //判断身份是否可以操作
        updateProDate: {}, //修改的参数
        upType: 4, //修改的类型，4：安全库存，5：提前期
      }
    },
    computed:{
      ...mapGetters([
        'showUpstatePro'
      ])
    },
    components:{
      upstateProduct,
    },
    created() {
      let self = this
      self.getProductLine()
      let authoritiesList = JSON.parse(localStorage.getItem('authoritiesList'))
      for (let i = 0; i < authoritiesList.length; i++){
        if (authoritiesList[i] == 'ROLE_CHECK'){
          self.canOperation = true
        }
      }
    },
    mounted() {
    },
    methods: {
      ...mapActions(['upstate']),
      //获取安全库存
      getProductLine(){
        let self = this
        self.$http.get(self.conURL + 'pm/api/safe_stock').then(res => {
          self.productLineList = res.data
        })
      },
      //修改安全库存/提前期
      updatePro(item,index){
        let self = this
        if (self.canOperation){
          self.upType = index
          self.upstate({key:'showUpstatePro',val:true})
          self.updateProDate = item;
        }
      },
      //组件返回值，重置列表刷新
      getBack(par){
        let self = this
        self.getProductLine()
      }
    }
  }
</script>

<style lang="less">
  .stock{
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 28px;
    padding-top: 0;
    box-sizing: border-box;
    .title{
      font-size: 20px;
      color: #333333;
    }
    .lists{
      display: flex;
      flex-direction: column;
      .list{
        width: 100%;
        border-bottom: 1px dashed #e5e5e5;
        display: flex;
        flex-direction: row;
        .list_title{
          font-size: 18px;
          color: #666666;
          width: 79%;
          margin-right: 1%;
          background: #fff;
          margin-bottom: 20px;
          padding: 19px;
          border-radius: 2px;
          border: 1px solid #e5e5e5;
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          cursor: pointer;
          label{
            letter-spacing: 2px;
            span{
              color: #3384dd;
            }
          }
        }
        .advance{
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          width: 20%;
          background: #fff;
          color: #666666;
          margin-bottom: 20px;
          padding: 19px;
          border-radius: 2px;
          border: 1px solid #e5e5e5;
          font-size: 16px;
          cursor: pointer;
          .ad_right{
            span{
              color: #3384dd;
            }
          }
        }
      }
      .list:last-child{
        border-bottom: none;
      }
    }
  }
</style>
